package com.education.business.service.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.business.mapper.system.ExamTaskMapper;
import com.education.business.service.BaseService;
import com.education.common.model.PageInfo;
import com.education.common.utils.FileUtil;
import com.education.model.dto.ExamTaskDto;
import com.education.model.request.PageParam;
import com.education.model.subproject.ExamTask;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamTaskService extends BaseService<ExamTaskMapper, ExamTask> {

    /**
     * 获取考试任务列表
     * @param pageParam
     * @return
     */
    public PageInfo<ExamTask> selectExamTaskInfoList(PageParam pageParam,ExamTask examTask) {
        Page<ExamTask> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.selectAll(page,examTask));
    }
    /**
     * 监考端
     */
    public ExamTask selectExamById(ExamTask examTask){
        return baseMapper.selectByIdTask(examTask);

    }


    /**
     * 修改状态
     * @param examTaskDto
     * @return
     */
    public int editStatus(ExamTaskDto examTaskDto){
        ExamTask examTask = new ExamTask();
        examTask.setStatu(examTaskDto.getStatu());
        examTask.setId(examTaskDto.getId());
        return  baseMapper.updateById(examTask);
    }

    /**
     * 查询单个考试任务
     * 读取并写入json文件
     * @param taskId
     * @return
     */
    public ExamTask ExamTaskById(int taskId){
        ExamTask examTasks = baseMapper.selectByTaskId(taskId);
        FileUtil.WriteFile("examTasks"+".json",FileUtil.tojson(examTasks));
        return baseMapper.selectByTaskId(taskId);
    }
    public int saveAll(ExamTask examTask){
        return baseMapper.saveAll(examTask);
    }
    public ExamTask selectByTaskId(int id){
        return baseMapper.selectByTaskId(id);
    }

//
//    /**
//     * 监考端获取考试任务名称、考试时间
//     */
//    public void selectById(ExamTask examTask){
//        return baseMapper.
//
//    }
}
